<?php
class CoverImageServiceImpl implements CoverImageService {

    private static $COVER_IMAGE_FILE = ".cover";

    private $fullServerPath = false;

    function __construct($fullServerPath) {
        $this->fullServerPath = $fullServerPath;
    }
    public function getCoverImage($path) {

        $currentDir = $this->fullServerPath . $path;
        if(file_exists($currentDir . "/" . self::$COVER_IMAGE_FILE)) {
            $lines = file($currentDir . "/" . self::$COVER_IMAGE_FILE);
            foreach ($lines as $line_num => $line) {
                $lineContent = trim($line);
                if(!StringUtils::startsWith($lineContent, "#")) {
                    $thumbUrl = $currentDir . "/.thumbs/" . $lineContent;
                    if(file_exists($thumbUrl)) {
                        return $thumbUrl;
                    }
                }
            }
        }
        return NULL;
    }

}
?>
